package net.wofly.finance.expense.web;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.wofly.finance.expense.domain.ExpenseType;
import net.wofly.finance.expense.service.IExpenseTypeService;
import net.wofly.finance.expense.validator.ExpenseAccountValidator;
import net.wofly.finance.expense.validator.ExpenseTypeValidator;
import net.wofly.framework.util.ReturnBean;

@Controller
@RequestMapping(value = "/api/finance/expense")
@Api(description = "报销类型管理")
public class ExpenseTypeController {
	
Logger logger = LoggerFactory.getLogger(ExpenseAccountController.class);
    
	@Autowired
	private IExpenseTypeService iExpenseTypeService ;
	
	
    @ApiOperation(value = "保存报销单费用类型")
    @RequestMapping(value = "/save", method = {RequestMethod.POST})
    @ResponseBody
	public ReturnBean<ExpenseType> save(@RequestBody ExpenseType expenseType){
    		String errorMessage = ExpenseTypeValidator.validateSaveExpenseTypeParams(expenseType) ;
        
		if (errorMessage.length() > 0) {
	        return new ReturnBean<>(-1, errorMessage);
	    }
    		
    		return iExpenseTypeService.save(expenseType) ;
    }
    
    @ApiOperation(value = "修改报销单费用类型")
    @RequestMapping(value = "/update", method = {RequestMethod.POST})
    @ResponseBody
	public ReturnBean<ExpenseType> update(@RequestBody ExpenseType expenseType){
    		
    		String errorMessage = ExpenseTypeValidator.validateUpdateExpenseTypeParams(expenseType) ;
        
		if (errorMessage.length() > 0) {
	        return new ReturnBean<>(-1, errorMessage);
	    }
    		
    		return iExpenseTypeService.update(expenseType) ;
    }
    
    @ApiOperation(value = "删除报销单费用类型")
    @RequestMapping(value = "/del", method = {RequestMethod.POST})
    @ResponseBody
	public ReturnBean<String> del(String expenseTypeID){
    		String errorMessage = ExpenseTypeValidator.validateExpenseTypeIDParams(expenseTypeID) ;
        
		if (errorMessage.length() > 0) {
	        return new ReturnBean<>(-1, errorMessage);
	    }
		
		return iExpenseTypeService.del(expenseTypeID) ;
    }
    
    @ApiOperation(value = "获取全部报销单费用类型列表")
    @RequestMapping(value = "/getAllExpenseTypeList", method = {RequestMethod.POST})
    @ResponseBody
	public ReturnBean<List<ExpenseType>> getAllExpenseTypeList(){
    		
    		return iExpenseTypeService.getAllExpenseTypeList() ;
    }
}
